
Class('mainui', 'linb.Com',{
    Instance:{
        //base Class for this com
        base:["linb.UI"], 
        //requried class for this com
        required:["linb.UI.Pane", "linb.UI.MenuBar"], 
        
        properties:{}, 
        events:{}, 
        iniResource:function(com, threadid){
        }, 
        iniComponents:function(){
            // [[code created by jsLinb UI Builder
            var host=this, children=[], append=function(child){children.push(child.get(0));};

            append((new linb.UI.Pane)
                .host(host,"pane6")
                .setDock("top")
                .setHeight(40)
            );

            host.pane6.append((new linb.UI.MenuBar)
                .host(host,"menubar1")
                .setItems([{"id":"system",
                "sub":[{"id":"mlogin", "caption":"登录系统"},
                {"id":"mlogout", "caption":"登出系统"},
                {"id":"musermanager", "caption":"用户管理"},
                {"id":"mquit", "caption":"退出系统"}], "caption":"系统"},
                {"id":"mdevice",
                "sub":[{"id":"madd_device", "caption":"设备信息添加"},
                {"id":"mmodify_device", "caption":"设备信息编辑"}], "caption":"设备管理"},
                {"id":"mresource",
                "sub":[{"id":"mmodify_resource", "caption":"设备资源管理"}], "caption":"资源管理"},
                {"id":"mplan",
                "sub":[{"id":"madd_plan", "caption":"增加计划"},
                {"id":"mmodify_plan", "caption":"编辑计划"},{"id":"mview_log","caption":"查看告警日志"}], "caption":"计划管理"},
                {"id":"mdevice_state",
                "sub":[{"id":"mview_state", "caption":"查看设备状态"},
                {"id":"mhistory_state", "caption":"查看历史状态"}], "caption":"设备状态"},
                {"id":"mabout", "caption":"关于"}])
                .onMenuSelected("_menubar1_onmenuselected")
                .setTagVar({"mlogin":0,"mlogout" : 0,"musermanager" : 0,"mquit" : 0,"madd_device" : 0,"mmodify_device" : 0,
                "mmodify_resource" : 0,"madd_plan" : 0,"mview_log" :0,"mmodify_plan" : 0,"mview_state" : 0,"mhistory_state" : 0})
            );

            return children;
            // ]]code created by jsLinb UI Builder
        }, 
        iniExComs:function(com, hreadid){
        }, 
        _menubar1_onmenuselected:function (profile, popProfile, item, src) {
            me = this;
            if (item.id == 'mlogin' && _.unserialize(me.menubar1.getTagVar()).mlogin == 0) {
                oo = _.unserialize(me.menubar1.getTagVar());
                oo.mlogin= 1;
                me.menubar1.setTagVar(_.serialize(oo));
                linb.ComFactory.newCom("userlogin",function(){
                myUser = this;
                myUser.show(true);
                myUser.setWhoisParent(me);
	            });
            }

            if (item.id == 'mhistory_state' && _.unserialize(me.menubar1.getTagVar()).mhistory_state == 0) {
                oo = _.unserialize(me.menubar1.getTagVar());
                oo.mhistory_state= 1;
                me.menubar1.setTagVar(_.serialize(oo));
                linb.ComFactory.newCom("viewmanager",function(){
                myUser = this;
                myUser.show(true);
                myUser.setWhoisParent(me);
	            });
            }
            
            if (item.id == 'madd_device' && _.unserialize(me.menubar1.getTagVar()).madd_device == 0) {
            	oo = _.unserialize(me.menubar1.getTagVar());
            	oo.madd_device = 1;
            	me.menubar1.setTagVar(_.serialize(oo));
            	linb.ComFactory.newCom("addDeviceinfo",function(){
            		dm = this;
            		dm.setWhoisParent(me);
            		dm.show(true);            		
            	});
            }            
            
            if (item.id == 'mmodify_device' && _.unserialize(me.menubar1.getTagVar()).mmodify_device == 0) {
            	oo = _.unserialize(me.menubar1.getTagVar());
            	oo.mmodify_device = 1;
            	me.menubar1.setTagVar(_.serialize(oo));
            	linb.ComFactory.newCom("devicemanager",function(){
            		dm = this;
            		dm.setWhoisParent(me);
            		dm.show(true);            		
            	});
            }

            if (item.id == 'mmodify_resource' && _.unserialize(me.menubar1.getTagVar()).mmodify_resource == 0) {
            	oo = _.unserialize(me.menubar1.getTagVar());
            	oo.mmodify_resource = 1;
            	me.menubar1.setTagVar(_.serialize(oo));
            	linb.ComFactory.newCom("resourcemanager",function(){
            		dm = this;
            		dm.setWhoisParent(me);
            		dm.show(true);            		
            	});
            }
            
            if (item.id == 'madd_plan' && _.unserialize(me.menubar1.getTagVar()).madd_plan == 0) {
            	oo = _.unserialize(me.menubar1.getTagVar());
            	oo.madd_plan = 1;
            	me.menubar1.setTagVar(_.serialize(oo));
            	linb.ComFactory.newCom("addPlan",function(){
            		dm = this;
            		dm.setWhoisParent(me);
            		dm.show(true);
            	})
            }

            if (item.id == 'mmodify_plan' && _.unserialize(me.menubar1.getTagVar()).mmodify_plan == 0) {
            	oo = _.unserialize(me.menubar1.getTagVar());
            	oo.mmodify_plan = 1;
            	me.menubar1.setTagVar(_.serialize(oo));
            	linb.ComFactory.newCom("PlanManager",function(){
            		dm = this;
            		dm.setWhoisParent(me);
            		dm.show(true);
            	})
            }            

            if (item.id == 'musermanager' && _.unserialize(me.menubar1.getTagVar()).musermanager == 0) {
                oo = _.unserialize(me.menubar1.getTagVar());
                oo.musermanager= 1;
                me.menubar1.setTagVar(_.serialize(oo));
                linb.ComFactory.newCom("usermanager",function(){
                myUser = this;
                myUser.show(true);
                myUser.setWhoisParent(me);
	            });
            }
        }, 
        setrole:function(role) {
            me = this;
            if (role == 'viewstate') {
                me.menubar1.updateItem('musermanager',{'disabled' : true});
                me.menubar1.updateItem('mdevice',{'disabled' : true});
                me.menubar1.updateItem('mresource',{'disabled' : true});    
                me.menubar1.updateItem('mplan',{'disabled' : true});
            }
            if (role == 'usermanager') {
                me.menubar1.updateItem('musermanager',{'disabled' : false});
                me.menubar1.updateItem('mdevice',{'disabled' : true});
                me.menubar1.updateItem('mresource',{'disabled' : true});    
                me.menubar1.updateItem('mplan',{'disabled' : true});
                me.menubar1.updateItem('mdevice_state',{'disabled' : true});
            }
            if (role == 'devicemanager') {
                me.menubar1.updateItem('musermanager',{'disabled' : true});
                me.menubar1.updateItem('mdevice',{'disabled' : false});
                me.menubar1.updateItem('mresource',{'disabled' : false});    
                me.menubar1.updateItem('mplan',{'disabled' : true});
            }
            if (role == 'administrator') {
                me.menubar1.updateItem('musermanager',{'disabled' : false});
                me.menubar1.updateItem('mdevice',{'disabled' : false});
                me.menubar1.updateItem('mresource',{'disabled' : false});    
                me.menubar1.updateItem('mplan',{'disabled' : false});
                me.menubar1.updateItem('mdevice_state',{'disabled' : false});
                
            }
            if (role == 'notLogin' || role == '') {
                me.menubar1.updateItem('musermanager',{'disabled' : true});
                me.menubar1.updateItem('mdevice',{'disabled' : true});
                me.menubar1.updateItem('mresource',{'disabled' : true});    
                me.menubar1.updateItem('mplan',{'disabled' : true});
                me.menubar1.updateItem('mdevice_state',{'disabled' : true});                
            }
        }
    }
});